package com.nuanshui.heatedloan.msgcenter.integration;

import com.nuanshui.heatedloan.msgcenter.model.SmsPushMsgBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.nuanshui.heatedloan.constant.RabbitMqQueue;
import com.nuanshui.heatedloan.middleware.rabbitmq.RabbitmqMessageSender;
import com.nuanshui.heatedloan.msgcenter.model.AliSmsNotificationCodeTemp;
import com.nuanshui.heatedloan.middleware.msgcenter.bean.MsgBody;
import com.nuanshui.heatedloan.msgcenter.model.MsgType;

import java.util.ArrayList;
import java.util.List;

/**
 * 发送消息的工具类
 * 尽量发送消息都用这个类, 可以异步发送, 然后把这个入口写好, 其他的就不要直接调用了
 * @Author: Gonzo
 * @Date 2017/4/6下午3:21
 * @since 1.4.2
 */
@Component
public class MsgTools {
	
	@Autowired
	public RabbitmqMessageSender rabbitmqMessageSender;

	/**
	 * 发送短信信息
	 * @param
	 * @since $
	 */
	public void sendSmsMsg(SmsPushMsgBody msgBody) {
		msgBody.setMsgType(MsgType.SMS_MSG);
		rabbitmqMessageSender.send(RabbitMqQueue.RABBIT_MQ_SEND_MSG,msgBody);
	}

	/**
	 * 发推送
	 * @Author: Gonzo
	 * @Date 2017/4/6下午3:20
	 * @since 1.4.2
	 */
	public void sendPushMsg(AppPushMsgBody msgBody) {
		rabbitmqMessageSender.send(RabbitMqQueue.RABBIT_MQ_SEND_MSG,msgBody);
	}

	public SmsPushMsgBody createSmsPushMsgBody(String bizType, AliSmsNotificationCodeTemp template)
	{
		SmsPushMsgBody msgBody  = new SmsPushMsgBody();
		msgBody.setMsgType(MsgType.SMS_MSG);
		msgBody.setBizType(bizType);
		msgBody.setTemplateCode(template.gettempCode());
		return msgBody;
	}

	public void sendComposeMsg(List<MsgBody> msgBody) {
		for (MsgBody item: msgBody) {
			rabbitmqMessageSender.send(RabbitMqQueue.RABBIT_MQ_SEND_MSG,item);
		}
	}

	public void sendComposeMsg(MsgBody... msgs)
	{
		List<MsgBody> list=new ArrayList<MsgBody>();
		for (MsgBody item:msgs) {
			list.add(item);
		}
		sendComposeMsg(list);
	}
}
